## Sid Meier's Civilization 4
## Copyright Firaxis Games 2005

# < edited by the ViSa Modpack Team >

import ScreenInput
import CvScreenEnums

# globals

from CvPythonExtensions import *
from CvTechLeakScreensEnums import *
import CvUtil
import PyHelpers
import CvViSaTechleakEventManager

gc = CyGlobalContext()
localText = CyTranslator()
ArtFileMgr = CyArtFileMgr()

class CvTechLeakScreen:
	
	def __init__(self):

		self.WIDGET_ID = "TechLeakWidget"
		self.screenWidgetData = {}		
		self.nWidgetCount = 0
		self.Z_BACKGROUND = -2.1
		self.Z_CONTROLS = self.Z_BACKGROUND - 0.2
		self.EventKeyDown=6
		self.currentUnit=0


	# This function is called from 'outside', namely from the event manager. 
			
	#Tech Leak Screen
	def interfaceScreen(self):
		
		screen = self.getScreen()
		
		# Get the screen height, width etc.
		self.calculateScreenWidgetData(screen)

		screen.showScreen(PopupStates.POPUPSTATE_IMMEDIATE, False)
		
		# draws the top and bottom panel of the screen
		self.drawScreenTop(screen)
		self.drawTechLeakLeft(screen)		
		self.drawScreenBottom(screen)



	# Returns the instance of the unit statistics screen.						
	def getScreen(self):
		return CyGInterfaceScreen("TechLeakScreen", CvScreenEnums.TECH_LEAK_SCREEN)
		
	def drawTechLeakLeft(self, screen):

                # initialize the information of the outbound techleak from us to other players		
		TechLeakDataLeft = CvViSaTechleakEventManager.objTechleak.getTechLeakMessageLeft(gc.getActivePlayer().getID())

		# initialize the information from the inbound techleak from other players to us
		TechLeakDataRight = CvViSaTechleakEventManager.objTechleak.getTechLeakMessageRight(gc.getActivePlayer().getID())
		
		# check True/False if we have been recieves techleak upon start at all
		# TechLeakRecieve = CvViSaTechleakEventManager.objTechleak.getFirstTimeTechRecieve(gc.getActivePlayer().getID())

		# if we did not recieve techleak this turn, but have been recieving before:
		if ( TechLeakDataRight == '' and gc.getActivePlayer().getTechLeakOccured()):
			TechLeakDataRight = "\n<font=4>You aren't recieving any Research points this turn!</font>\n"

                # if we never recieved techleak before:
		if not ( gc.getActivePlayer().getTechLeakRecieved() ):
			TechLeakDataRight = "\n<font=4>You haven't recieved any Research points yet</font>\n"
		
		# Defines the structure of the screen
		screen.addPanel(PANEL_LEFT_ID, u"", u"", True, False, self.SCREEN_TITLE_PANEL_LEFT_X, self.SCREEN_TITLE_PANEL_LEFT_Y, self.SCREEN_TITLE_PANEL_LEFT_WIDTH, self.SCREEN_TITLE_PANEL_LEFT_HEIGHT, PanelStyles.PANEL_STYLE_MAIN )
		screen.addMultilineText(PANEL_LEFT_TEXT_ID, TechLeakDataLeft, self.SCREEN_TITLE_PANEL_LEFT_TEXT_X, self.SCREEN_TITLE_PANEL_LEFT_TEXT_Y, self.SCREEN_TITLE_PANEL_LEFT_TEXT_WIDTH, self.SCREEN_TITLE_PANEL_LEFT_TEXT_HEIGHT, WidgetTypes.WIDGET_GENERAL, -1, -1, CvUtil.FONT_LEFT_JUSTIFY)
		screen.addPanel(PANEL_RIGHT_ID, u"", u"", True, False, self.SCREEN_TITLE_PANEL_RIGHT_X, self.SCREEN_TITLE_PANEL_RIGHT_Y, self.SCREEN_TITLE_PANEL_RIGHT_WIDTH, self.SCREEN_TITLE_PANEL_RIGHT_HEIGHT, PanelStyles.PANEL_STYLE_MAIN )
		screen.addMultilineText(PANEL_RIGHT_TEXT_ID, TechLeakDataRight, self.SCREEN_TITLE_PANEL_RIGHT_TEXT_X, self.SCREEN_TITLE_PANEL_RIGHT_TEXT_Y, self.SCREEN_TITLE_PANEL_RIGHT_TEXT_WIDTH, self.SCREEN_TITLE_PANEL_RIGHT_TEXT_HEIGHT, WidgetTypes.WIDGET_GENERAL, -1, -1, CvUtil.FONT_LEFT_JUSTIFY)
		screen.hide(BOTTOM_PANEL_ID)
		screen.moveToFront(EXIT_TEXT_PANEL_ID)
				
	
	# Draws the top bar of the "Techleak" screens
	def drawScreenTop(self, screen):
		screen.setDimensions(0, 0, self.SCREEN_WIDTH, self.SCREEN_HEIGHT)
		screen.addDrawControl(BACKGROUND_ID, ArtFileMgr.getInterfaceArtInfo("SCREEN_BG_OPAQUE").getPath(), 0, 0, self.SCREEN_WIDTH, self.SCREEN_HEIGHT, WidgetTypes.WIDGET_GENERAL, -1, -1 )
		screen.addPanel(SCREEN_TITLE_PANEL_ID, u"", u"", True, False, self.TOP_PANEL_X, self.TOP_PANEL_Y, self.TOP_PANEL_WIDTH, self.TOP_PANEL_HEIGHT, PanelStyles.PANEL_STYLE_TOPBAR )
		screen.setText(SCREEN_TITLE_TEXT_PANEL_ID, "Background", self.SCREEN_TITLE_TEXT_PANEL, CvUtil.FONT_CENTER_JUSTIFY, self.SCREEN_TITLE_TEXT_PANEL_X, self.SCREEN_TITLE_TEXT_PANEL_Y, self.Z_CONTROLS, FontTypes.TITLE_FONT, WidgetTypes.WIDGET_GENERAL, -1, -1)


		
	def hideScreen(self):
		screen = self.getScreen()
		screen.hideScreen()

		

	# Draws the bottom bar of the "Techleak" screen
	def drawScreenBottom(self, screen):
		screen.addPanel(BOTTOM_PANEL_ID, u"", u"", True, True, self.BOTTOM_PANEL_X, self.BOTTOM_PANEL_Y, self.BOTTOM_PANEL_WIDTH, self.BOTTOM_PANEL_HEIGHT, PanelStyles.PANEL_STYLE_BOTTOMBAR )
		screen.setText(EXIT_TEXT_PANEL_ID, "Background", self.EXIT_TEXT_PANEL, CvUtil.FONT_RIGHT_JUSTIFY, self.EXIT_TEXT_PANEL_X, self.EXIT_TEXT_PANEL_Y, self.Z_CONTROLS, FontTypes.TITLE_FONT, WidgetTypes.WIDGET_CLOSE_SCREEN, -1, -1 )


	# Calculates the screens widgets positions, dimensions, text, etc.
	def calculateScreenWidgetData(self, screen):
		' Calculates the screens widgets positions, dimensions, text, etc. '
		
		# The border width should not be a hard coded number
		self.BORDER_WIDTH = 4
		
		self.SCREEN_WIDTH = screen.getXResolution()
		self.SCREEN_HEIGHT = screen.getYResolution()

		self.BOTTOM_PANEL_WIDTH = self.SCREEN_WIDTH
		self.BOTTOM_PANEL_HEIGHT = 55
		self.BOTTOM_PANEL_X = 0
		self.BOTTOM_PANEL_Y = self.SCREEN_HEIGHT - 55

		self.TOP_PANEL_WIDTH = self.SCREEN_WIDTH
		self.TOP_PANEL_HEIGHT = 55
		self.TOP_PANEL_X = 0
		self.TOP_PANEL_Y = 0

		# Handle the buttons
		self.EXIT_TEXT_PANEL = u"<font=4>" + localText.getText("TXT_KEY_TECHLEAK_EXIT", ()) + "</font>"
		self.EXIT_TEXT_PANEL_X = self.SCREEN_WIDTH - 55
		self.EXIT_TEXT_PANEL_Y = self.SCREEN_HEIGHT - 40

		self.SCREEN_TITLE_TEXT_PANEL = u"<font=4b>" + localText.getText("TXT_KEY_TECHLEAK_TOP", ()) + "</font>"
		self.SCREEN_TITLE_TEXT_PANEL_X = self.SCREEN_WIDTH/2
		self.SCREEN_TITLE_TEXT_PANEL_Y = 8
	

		# Left Panel settings
		self.SCREEN_TITLE_PANEL_LEFT_WIDTH = self.SCREEN_WIDTH / 2 - 20
		self.SCREEN_TITLE_PANEL_LEFT_HEIGHT = self.SCREEN_HEIGHT - ( 2 * self.BORDER_WIDTH + self.BOTTOM_PANEL_HEIGHT + self.TOP_PANEL_HEIGHT )
		self.SCREEN_TITLE_PANEL_LEFT_X = 15
		self.SCREEN_TITLE_PANEL_LEFT_Y = self.TOP_PANEL_HEIGHT

		self.SCREEN_TITLE_PANEL_LEFT_TEXT_WIDTH = self.SCREEN_WIDTH / 2 - 40
		self.SCREEN_TITLE_PANEL_LEFT_TEXT_HEIGHT = self.SCREEN_HEIGHT - ( 2 * self.BORDER_WIDTH + self.BOTTOM_PANEL_HEIGHT + self.TOP_PANEL_HEIGHT + 100)
		self.SCREEN_TITLE_PANEL_LEFT_TEXT_X = 25
		self.SCREEN_TITLE_PANEL_LEFT_TEXT_Y = self.TOP_PANEL_HEIGHT + 20

		# Right Panel settings
		self.SCREEN_TITLE_PANEL_RIGHT_WIDTH = self.SCREEN_WIDTH / 2 - 20
		self.SCREEN_TITLE_PANEL_RIGHT_HEIGHT = self.SCREEN_HEIGHT - ( 2 * self.BORDER_WIDTH + self.BOTTOM_PANEL_HEIGHT + self.TOP_PANEL_HEIGHT )
		self.SCREEN_TITLE_PANEL_RIGHT_X = self.SCREEN_WIDTH / 2 + 5
		self.SCREEN_TITLE_PANEL_RIGHT_Y = self.TOP_PANEL_HEIGHT

		self.SCREEN_TITLE_PANEL_RIGHT_TEXT_WIDTH = self.SCREEN_WIDTH / 2 - 40
		self.SCREEN_TITLE_PANEL_RIGHT_TEXT_HEIGHT = self.SCREEN_HEIGHT - ( 2 * self.BORDER_WIDTH + self.BOTTOM_PANEL_HEIGHT + self.TOP_PANEL_HEIGHT + 100)
		self.SCREEN_TITLE_PANEL_RIGHT_TEXT_X = self.SCREEN_WIDTH / 2 + 15
		self.SCREEN_TITLE_PANEL_RIGHT_TEXT_Y = self.TOP_PANEL_HEIGHT + 20


		

		

		

	
			
